

package com.morrislabs.graph
{
	import flash.display.GradientType;
	import flash.display.InterpolationMethod;
	import flash.display.SpreadMethod;
	
	
	import mx.core.UIComponent;
	import flash.text.TextField;
	import flash.display.BitmapData;

	public class GraphNodeRender extends UIComponent
	{
		
		public function set text(s: String): void {
			_text = s;
			invalidateDisplayList();
		}

		public function get text(): String {
			return _text;
		}		
		
		/** the color that this circle will be */
		public function set color(i: int): void {
			_color = i;
			
			// don't redraw immediately, because maybe the code that's calling us is
			// going to change several settings, and we don't want to redraw for each 
			// setting change. Instead, tell the flex framework that
			// we need to be redrawn; the framework will ensure that updateDisplayList
			// is invoked after all scripts have finished executing.
			invalidateDisplayList(); 
		}
		
		
		
		/** our current color setting. */
		private var _text: String = " ";
		private var _color: int;
		
		/** redraws the component, using our current color, height, and width settings.
		 *  This function is called whenever the flex framework decides it's time to redraw the component. */
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

//			var textfield:TextField = new TextField;
//			textfield.text = this.text;
//			textfield.textColor = 0xffffff;
//			var bitmapdata:BitmapData = new BitmapData(textfield.textWidth, textfield.textHeight, true, 0x00000000);
			
			graphics.clear();
			graphics.beginGradientFill(GradientType.RADIAL, [0xffffff, _color], [1, 1], [0, 127], 
				null, SpreadMethod.PAD, InterpolationMethod.RGB, 0.75);
			graphics.drawCircle(unscaledWidth / 2, unscaledHeight / 2, unscaledHeight / 2);
			graphics.endFill();
			
			//bitmapdata.draw(textfield);
		}
	}
}